﻿(function ($) {

    jQuery.validator.unobtrusive.adapters.add("requiredif", ["otherfield", "mode"], function (options) {
        options.rules['required'] = "#" + options.params.otherfield + ((options.params.mode == 0) ? ":blank" : ":filled");
        options.messages['required'] = options.message;
    });

    jQuery.validator.unobtrusive.adapters.add("requireiftipopropiedad", ["otherfield", "tipospropiedadesquerequieren"], function (options) {
        options.rules['required'] = function () {
            var tipoPropiedadSelected = jQuery("#" + options.params.otherfield).val();
            if (options.params.tipospropiedadesquerequieren.indexOf(tipoPropiedadSelected) == -1) {
                    return false;
                } else {
                    return true;
                }                
            };
        options.messages['required'] = options.message;
    });

} (jQuery));